// 获取XmlHttpRequest对象
function createXmlHttpRequest() {
	if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
}

//获取url后的参数值
function GetRequest() {
	   var url = location.search; //获取url中"?"符后的字串
	   var theRequest = new Object();
	  
	   if (url.indexOf("?") != -1) {
	      var str = url.substr(1);
	      strs = str.split("&");
	      for(var i = 0; i < strs.length; i ++) {
	         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
	      }
	      
	   }
	   return theRequest;
}

//获取url路径#后的参数值
function GetParam(){
	
	var Url=top.window.location.href;
	var u='',g='';
	if(Url.indexOf("#")){
		u=Url.split("#");
	}else if(Url.indexOf("?")){
		u=Url.split("?");
	}
	if (u.length==1){
		g='';
	}else{
		g=u[1]; 
	}
	
	   return g;
}
//获取项目名
var pathName=window.document.location.pathname;
var ctx=pathName.substring(0,pathName.substr(1).indexOf('/')+1);

function GetUrl(){
	 var pathName=window.document.location.pathname;
	 var projectName=pathName.substring(pathName.substr(1).indexOf('/')+1);
	var url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx31cf436485b2fdf8&redirect_uri=http%3a%2f%2f203.195.189.85%2flifesense-healthcenter%2fwechat%2fauthx4HTML%3ft%3d"+projectName+"&response_type=code&scope=snsapi_base&state=gh_4bc17495d97a#wechat_redirect";

	return url;
}

//
function GetRequestValue(){
//	var param=new Object();
//	param = GetRequest();
	
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
					jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					if(jsonData.accountId != null){
						GetMemberId(jsonData.accountId);
					}
			}
		}
	};
	var url = ctx+"/wechat/ajax_webAuthorize";
//	xhr.open("post", url + "?code=" + param["code"] +"&&state="+param["state"]+"&&scope="+param["scope"]+"&&mathNum="+Math.random(), true);
	xhr.open("post", url+"?num=1", true);
	xhr.send();
}

function GetMemberId(accountId){
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
				document.getElementById("memberId").value=json;
				//初始化数据	
				ajaxLoadData();
			}
		}
	};
	var url = ctx+"/wechat/ajax_openId";
	xhr.open("post", url + "?accountId="+accountId+"&&mathNum="+Math.random(), true);
	xhr.send();
}

//显示块
function showDOM(id){
	var dom = document.getElementById(id);
	dom && (dom.style.display = 'block');
}
//隐藏块
function hiddenDOM(id){
	var dom = document.getElementById(id);
	dom && (dom.style.display = 'none');
}